package com.game77.guessTheWords2.scene;

import android.view.KeyEvent;

import com.game77.guessTheWords2.core.StageManager;
import com.game77.guessTheWords2.layer.StageLayer;
import com.game77.guessTheWords2.util.GameUtil;
import com.wiyun.engine.nodes.Scene;

/**
 * 关卡选择场景
 * 
 * @author Administrator
 * 
 */
public class StageScene extends Scene {
	private static StageScene instance = null;
	private static Object sync_obj = new Object();

	StageLayer stageLayer;

	protected StageScene() {
		stageLayer = new StageLayer();
		stageLayer.setTouchEnabled(true);
		addChild(stageLayer);
	}

	public static StageScene make() {
		synchronized (sync_obj) {
			if (instance == null) {
				instance = new StageScene();
			}
			return instance;
		}
	}

	public void refreshStages() {
		stageLayer.refreshStages();
		// TODO lc 需要根据章节存放上次的游戏关卡
		stageLayer.scollToIndex(StageManager.instance
				.getLastClassStageIndex(StageManager.instance.getLastClass()));
	}

	@Override
	public boolean wyKeyDown(KeyEvent event) {

		if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
			GameUtil.switchSceneNormalFast(ClassChooseScene.make());
			ClassChooseScene.make().refreshClassInfos();
			ClassChooseScene.make().updateCoins();
			return true;
		}
		return super.wyKeyDown(event);
	}
}
